package com.wjs.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wjs.dao.TeaMapper;
import com.wjs.entity.Tea;
import com.wjs.service.TeaService;
import com.wjs.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class TeaServiceImpl implements TeaService {
    SqlSession session = MybatisUtils.getSession();
    TeaMapper tm=session.getMapper(TeaMapper.class);

    @Override
    public List<Tea> selectAll() {
        List<Tea>list=tm.selectAll();
        return list;
    }

    @Override
    public PageInfo<Tea> selectAllByPage(int curPage,int pageSize) {
        //告知要其分页了，设置分页信息，第一页和一页查三条
        PageHelper.startPage(curPage,pageSize);
        //获取查询全部的集合
        List<Tea>list=tm.selectAll();
        //将集合封装
        PageInfo<Tea> pi=new PageInfo<Tea>(list);

        return pi;
    }

    @Override
    public void addTea(Tea tea) {
        tm.addTea(tea);
        session.commit();
    }

    @Override
    public void update(Tea tea) {
        tm.update(tea);
        session.commit();
    }

    @Override
    public Tea selectById(int id) {
        return tm.selectById(id);
    }

    @Override
    public void deleteByID(int id) {
        tm.deleteByID(id);
        session.commit();
    }

    @Override
    public void batchDle(int[] ids) {
        tm.batchDle(ids);
        session.commit();
    }
}
